package org.lanqiao.api.admin;

import java.io.IOException;
import java.util.UUID;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.lanqiao.service.OrderServiceImpl;
import org.lanqiao.util.PaymentUtil;


/**
 * 支付接口
 * @author Lanqiao08
 *
 */
@WebServlet("/order/YeePayServlet")
public class YeePayServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
      /**
       	* 支付接口方法
       */
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//		String userId=request.getParameter("userId");
		String p0_Cmd = "Buy"; 
		String p1_MerId = "10001126856";
		String p2_Order = request.getParameter("orderId");
		String p3_Amt = "0.01"; //
		String p4_Cur = "CNY"; //
		String p5_Pid = ""; //
		String p6_Pcat = ""; // 
		String p7_Pdesc = ""; //
		String p8_Url = "http://localhost:8020/明天/index.html?__hbt=1534602451597?orderid="+p2_Order; 
		String p9_SAF = ""; 
		String pa_MP = ""; 
		String pd_FrpId = "";
		String pr_NeedResponse = "1"; 
		String keyValue = "69cl522AV6q613Ii4W6u8K6XuW8vM1N6bFgyv769220IuYe9u37N4y7rI4Pl"; 
		String hmac = PaymentUtil.buildHmac(p0_Cmd, p1_MerId, p2_Order, p3_Amt,
				p4_Cur, p5_Pid, p6_Pcat, p7_Pdesc, p8_Url, p9_SAF, pa_MP,
				pd_FrpId, pr_NeedResponse, keyValue);//
		StringBuffer sb = new StringBuffer("https://www.yeepay.com/app-merchant-proxy/node?");
		sb.append("p0_Cmd=").append(p0_Cmd).append("&");
		sb.append("p1_MerId=").append(p1_MerId).append("&");
		sb.append("p2_Order=").append(p2_Order).append("&");
		sb.append("p3_Amt=").append(p3_Amt).append("&");
		sb.append("p4_Cur=").append(p4_Cur).append("&");
		sb.append("p5_Pid=").append(p5_Pid).append("&");
		sb.append("p6_Pcat=").append(p6_Pcat).append("&");
		sb.append("p7_Pdesc=").append(p7_Pdesc).append("&");
		sb.append("p8_Url=").append(p8_Url).append("&");
		sb.append("p9_SAF=").append(p9_SAF).append("&");
		sb.append("pa_MP=").append(pa_MP).append("&");
		sb.append("pd_FrpId=").append(pd_FrpId).append("&");
		sb.append("pr_NeedResponse=").append(pr_NeedResponse).append("&");
		sb.append("hmac=").append(hmac);
//		OrderServiceImpl order=new OrderServiceImpl();
//		order.orderSettlement(p2_Order);
		response.sendRedirect(sb.toString());
	}
}
